package dao

import (
	"gorm.io/driver/postgres"
	"gorm.io/gorm"
)

const (
	host     = ""
	port     = ""
	user     = ""
	password = ""
	dbname   = ""
)

func ConnectToDatabase() (*gorm.DB, error) {

	//connStr := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", host, port, user, password, dbname)
	//constStr := fmt.Sprintf(`postgres://postgres:1234ABcd@127.0.0.1:5432/test?sslmode=disable`)
	//
	//DB, err := gorm.Open(postgres.Open(constStr))

	dsn := "host=127.0.0.1 user=postgres password=1234ABcd dbname=test port=5432 sslmode=disable TimeZone=Asia/Shanghai"
	db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})

	if err != nil {
		return nil, err
	}

	return db, nil
}
